package org.big.kafkacluster;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Service;

@Service
public class KafkaProducerService {

    private static final String TOPIC_NAME = "demo-topic"; // 定义 Topic 名称

    @Autowired
    private KafkaTemplate<String, String> kafkaTemplate;

    public void sendMessage(String message) {
        // 发送消息到指定的 Topic
        kafkaTemplate.send(TOPIC_NAME, message);

        System.out.println("消息发送成功: " + message);
    }
}